<?php

class Blog extends Controller {

	function Blog()
	{
		//Contructor
		parent::Controller();
		$this->load->model('blogmodel');
		$this->load->model('usermodel');
		$this->load->library('form_validation');

	}

	function view()
	{
		$blogId = $this->uri->segment(3);
		$blogOwner = $this->blogmodel->getBlogOwner($blogId);
		$data['titlebar'] = "Panoramap.in.th | Blog";
		$data['blogOwner'] = $this->blogmodel->getBlogOwner($blogId);
		$data['lastBlog'] = $this->blogmodel->getBlog($blogOwner, 10);
		$data['lastComment'] = $this->blogmodel->getLastComment($blogOwner, 10);
		$data['blog'] = $this->blogmodel->getBlog($blogOwner, 1, $blogId);
		$this->load->view('blog_user_view', $data);
	}
	
	function blog_comment()
	{
		$this->form_validation->set_rules('blog_comment', 'Comment', 'trim|required|xss_clean');
		$url = $this->input->post('redirectURL');

		if($this->form_validation->run() == FALSE)
		{
			redirect($url);	
		}
		else
		{
			$this->blogmodel->blogComment($this->session->userdata('userId'));
			redirect($url);	
		}
	}

}